package org.prism.thread.tick;

public class SellTick04 extends Thread{
    //一共一百张票
    private static int ticket = 100;

    @Override
    public void run() {
        while (true){
            show();
        }
    }
    public synchronized static void show(){
        if(ticket > 0){
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "卖票: 票号" + ticket);
            ticket--;
        }
    }
}

class SellTickTest04{
    public static void main(String[] args) {
        Thread t1 = new SellTick04();
        Thread t2 = new SellTick04();
        Thread t3 = new SellTick04();

        t1.setName("窗口一");
        t2.setName("窗口二");
        t3.setName("窗口三");

        t1.start();
        t2.start();
        t3.start();
    }


}
